package docker

/*

	目录：
		1.启动mysql容器失败
		2.启动容器后，进入容器内部，使用mysql -uroot -p 报错
			ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)


-----------启动mysql容器失败-----------
	经过 docker-201* 命令


		--错误
		docker run -it --privileged=true -d  --name mysql-master -p 3307:3306 \
		-v /home/zydh/docker/etc/mysql-master/conf:/etc/mysql \
		-v /home/zydh/docker/volume/mysql-master/data:/var/lib/mysql \
		-v /home/zydh/logs/mysql-master/log:/var/log/mysql	 \
		-e MYSQL_ROOT_PASSWORD=root \
		mysql  --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci


		启动失败，使用docker ps -a 查看

root@VM-4-8-debian:/home/zydh/docker/volume# docker ps -a
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS                      PORTS                                                                                      NAMES
37ab91d503d0   mysql     "docker-entrypoint.s…"   46 seconds ago   Exited (1) 37 seconds ago                                                                                              mysql-master


		查看日志  docker logs 容器id

root@VM-4-8-debian:/home/zydh/docker/volume# docker logs 37ab91d503d0
2022-10-07 09:48:02+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2022-10-07 09:48:02+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-10-07 09:48:02+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2022-10-07 09:48:02+00:00 [Note] [Entrypoint]: Initializing database files
2022-10-07T09:48:02.582149Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.27) initializing of server in progress as process 42
2022-10-07T09:48:02.592885Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-10-07T09:48:03.554641Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-10-07T09:48:06.091758Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-10-07T09:48:06.091790Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-10-07T09:48:06.185016Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2022-10-07 09:48:11+00:00 [Note] [Entrypoint]: Database files initialized
2022-10-07 09:48:11+00:00 [Note] [Entrypoint]: Starting temporary server
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2022-10-07T09:48:11.557614Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2022-10-07 09:48:11+00:00 [ERROR] [Entrypoint]: Unable to start server.
root@VM-4-8-debian:/home/zydh/docker/volume#

		错误：Error on realpath()

解决：
	https://blog.csdn.net/weixin_26845891/article/details/113213596?
	https://blog.csdn.net/Baby_lucy/article/details/108218185


	原因：当指定了外部配置文件与外部存储路径时，也需要指定 /var/lib/mysql-files的外部目录
		注解：兄弟 你上述情形是不需要挂载mysql-files的，当将mysql容器的my.cnf挂载到宿主机的时候 才需要加上后面的mysql-files


	正确：   与docker-201*比较，挂载配置文件 :/etc/mysql/conf.d 有区别

		docker run -it --privileged=true -d  --name mysql-master -p 3307:3306 \
		-v /home/zydh/docker/lib/mysql/mysql-files:/var/lib/mysql-files/  \
		-v /home/zydh/docker/etc/mysql-master/conf:/etc/mysql \
		-v /home/zydh/docker/volume/mysql-master/data:/var/lib/mysql \
		-v /home/zydh/logs/mysql-master/log:/var/log/mysql	 \
		-e MYSQL_ROOT_PASSWORD=root \
		mysql  --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci


		加入该句
		#-v /home/zydh/docker/lib/mysql/mysql-files:/var/lib/mysql-files/




-----------启动容器后，进入容器内部，使用mysql -uroot -p 报错 -----------

root@VM-4-8-debian:/home/zydh/docker/etc/mysql-master/conf# docker exec -it 5467b10bf5c2 /bin/bash
root@5467b10bf5c2:/# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
root@5467b10bf5c2:/#

		问题：
			这种类型的提示是账号密码不对或者账号不存在的现象
			因为mysql安装完后，root的密码默认为空

		参考资料：
		https://cloud.tencent.com/developer/article/2019023


		------使用docker--------
			查看 docker-200-001*


		------未使用docker--------

//1.首先关闭mysql
service mysqld stop

//2.查看mysql状态
service mysqld status

//3.设置使用命令跳过输入密码过程
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

//4.另开一个窗口--登录mysql--不要输入密码,直接回车
mysql -uroot -p

//5.使用一下mysql数据库--指定数据库
use mysql;

//6.查看mysql数据库中user表，用户等于root的用户,有一下显示就可以
select 'user' from user where user='root';

//7.为user=root的用户设置密码为123456
//update user set password=PASSWORD('123456') where user='root';
# 原来是mysql数据库下已经没有password这个字段了，password字段改成了authentication_string

update user set authentication_string='123456' where user='root' and host='localhost';
update user set authentication_string='123456' where user='root';

//8.刷新使之生效，并退出
flush privileges;
exit

//9.重启mysql
service mysqld restart

//10.查看mysql状态
service mysqld status

//11.正常登录
mysql -u root -p 123456





*/
